﻿using HandyControl.Controls;
using Prism.Events;
using System;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using WpfAGVSystem.Common;
using WpfAGVSystem.Views.SmallView;

namespace WpfAGVSystem.Views
{
    /// <summary>
    /// Interaction logic for Login
    /// </summary>
    public partial class Login : UserControl
    {
        HandyControl.Controls.Dialog dialog;
        public Login(IEventAggregator _eventAggregator)
        {
            
            InitializeComponent();
            #region 数据验证

            //tttt.VerifyFunc = new Func<string, HandyControl.Data.OperationResult<bool>>(x => {
            //    if (x == String.Empty)
            //    {
            //        return new HandyControl.Data.OperationResult<bool>() { Data=false,Message="用户名不可为空" };
            //    }
            //    else 
            //    {
            //        return new HandyControl.Data.OperationResult<bool>() { Data = true};
            //    }
            //});
            #endregion 
            //  this.miantt.Background =new SolidColorBrush(Color.FromRgb(1,95,104));
            _eventAggregator.GetEvent<LoginEvent>().Subscribe(arg =>
            {
                if (arg)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        dialog = Dialog.Show(new WaitView());
                    }));
                }
                else 
                {
                    if (dialog!=null)
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            dialog.Close();
                            dialog = null;
                            
                        }));
                    }
                }
           
            });

        }
        
    }
}
